#include <vector>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <limits>
#include <cstdlib>
#include <ctime>
#include "binary_search.h"
#include <sstream>
#include <string>
#include <boost/lexical_cast.hpp>
#include <armadillo>

using namespace std;
using namespace boost;

template<typename T, int size>
int GetArrLength(T(&)[size]){
	return size;
}

std::string IntToStr( int n )
{
	return lexical_cast<std::string>(n);
}

double unifRand()
{
    return rand() / double(RAND_MAX);
}

void seed()
{
    srand(time(0));
}

vector<int> process_Ak(Mat<int> A) {
	
}



int score(double arr[], double key) {
	int index = binarySearch(arr, 0, 3, key);
	return index;
}

int main()
{
	vector< vector<int> > stats;
	int d_arr[4];
	d_arr[0] = 1;
	d_arr[1] = 3;
	d_arr[2] = 5;
	d_arr[3] = 7;
	int sum = 0;
	int i = 0;
	int len = GetArrLength(d_arr);
	vector<int> count_arr (4);
	
	for (;i < len;i++) {
		sum += d_arr[i];
	}
	
	double prob [4];
	
	for (int i = 0; i < 4; i++) {
		 prob[i] = 0;
		 cerr << prob[i] << endl;
	}
	for (i = 1;i < len;i++) {
		double p = (double) d_arr[i-1] / sum;
		prob[i] = (double) prob[i-1] + p;
	}
	
	//cerr << binarySearch(prob, 0, 3, 0.6) << endl;
	
	for (int j = 0; j < 10000000; j++)  {
		int index = score(prob, unifRand());
		if (index < 0)
			index = abs(index)-2;
		count_arr[index]++;
	}
	//stats.push_back(count_arr);
	//count_arr = vector<int>(4);
	//seed();
    
	
	for (i = 0; i < len; i++) {
		cerr << count_arr[i] << " ";
		cerr << "(" << (10000000 * d_arr[i]/sum) << ") " << endl;
	}
	cerr << endl;
   return 0;
}